<div class="hte-settings-panel hte-webkit-scrollbar">
	<div class="hte-settings-inner">

	<ul class="nav nav-tabs messager-nav nav-justified">
		<li class="active"><a href="#theme" data-toggle="tab">
				<h4>主题</h4>
		</a></li>
		<li><a href="#wallpaper" data-toggle="tab">
				<h4>壁纸</h4>
		</a></li>
	</ul>
	<div class="tab-content" style="height: 100%">
		<div class="tab-pane fade in active hte-theme-list" id="theme" >
			<div class="hte-theme-item" style="background-color: rgb(31,91,183);" data-theme="blue"></div>
			<div class="hte-theme-item" style="background-color: rgb(89,183,40);" data-theme="green"></div>
			<div class="hte-theme-item" style="background-color: rgb(155,29,171);" data-theme="purple"></div>
			<div class="hte-theme-item" style="background-color: rgb(204,53,53);" data-theme="red"></div>
			<div class="hte-theme-item" style="background-color: rgb(208, 150, 21);" data-theme="orange"></div>
			<div class="hte-theme-item" style="background-color: rgb(84, 74, 74);" data-theme="gray"></div>
			<div class="hte-theme-item" style="background-color: rgb(47, 128, 82);" data-theme="cyan"></div>
		</div>
		<div class="tab-pane fade hte-wallpaper-list" id="wallpaper">
				<ul>
					<li class="wallpaper-actions">
						<div style="width:100%">
							<button class='btn btn-default btn-upload-wallpaper' >上传壁纸</button>
							<input type="file" class="wallpaper-upload-file" style="display:none"/>
							<button class='btn btn-default btn-link-wallpaper' >使用网络图片</button>
						</div>
					</li>
					<li><img src="images/wallpaper/10.jpg"></li>
					<li><img src="images/wallpaper/11.jpg"></li>
					<li><img src="images/wallpaper/cloud.jpg"></li>
					<li><img src="images/wallpaper/Wood.jpg"></li>
					<li><img src="images/wallpaper/Yuanye.jpg"></li>
					<li><img src="images/wallpaper.jpg"></li>
				</ul>
		</div>
	</div>
</div>
</div>
<script type="text/javascript">

	$(document).off("click.hte.wallpaper.link");
	$(document).on("click.hte.wallpaper.link",".btn-link-wallpaper",function(){
		HteOS.Messager.prompt("设置壁纸","请输入网络图片链接",[{
					name : 'url',
					label : '图片链接',
					inputType:"url"
				}],function(btn,values){
					if(btn == 'yes'){
						if(values.url){
						console.log(values.url);
						 var strRegex = "^((https|http|ftp|rtsp|mms)?://)"  
						         + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@  
						         + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184  
						         + "|" // 允许IP和DOMAIN（域名） 
						         + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.  
						         + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名  
						        + "[a-z]{2,6})" // first level domain- .com or .museum  
						        + "(:[0-9]{1,4})?" // 端口- :80  
						        + "((/?)|" // a slash isn't required if there is no file name  
						        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; 
						    var re = new RegExp(strRegex),result = re.test(values.url);
					        if (result){
					           HteOS.EventManager.trigger('hte.wallpaper.change',values.url);
					        }else{ 
					        	$(".hte-messager-tip").text("输入的地址不是正确的URL地址");
					        	return false;
					        }
						}
					}
				});
	});
	
	$(document).off("click.hte.wallpaper.upload");
	$(document).on("click.hte.wallpaper.upload",".btn-upload-wallpaper",function(){
		$(".wallpaper-upload-file").click();
	});
	
	$(function(){
		$(".wallpaper-upload-file").off();
		$(".wallpaper-upload-file").change(
			function() {
				var file = this.files[0];
				if (file.type != "image/png"
						&& file.type != "image/gif"
						&& file.type != "image/jpeg") {
					HteOS.Messager.alert("设置壁纸","请选择图片文件");
				} else if (file.size > 1024 * 1024 * 10) {
					HteOS.Messager.alert("设置壁纸","图片文件太大");
				} else {
					upload(file);
				}
			});
		
		var upload = function(file){
			var button = $(".btn-upload-wallpaper");
			button.html("正在上传..");
			button.attr("disabled", "disabled");
			var xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 ) {
					button.html("上传壁纸");
					button.removeAttr("disabled");
					if(xhr.status == 200){
						var result = JSON.parse(xhr.responseText);
						if(result.success){
							HteOS.Notification.show("","应用消息","上传壁纸成功");
							//HteOS.EventManager.trigger('hte.wallpaper.change',result.message);
							HteOS.Settings.setWallpaper(result.message);
						}else{
							HteOS.Notification.show("","应用消息","上传壁纸失败：" + result.message);
						}
					}
					else{
						HteOS.Notification.show("","应用消息","上传壁纸失败：" + xhr.status + " " + xhr.statusText);
					}
				}
			}
			xhr.open("POST", HteOS.API.WALLPAPER_UPLOAD, true);
			var fd = new FormData();
			fd.append("wallpaper", file);
			xhr.send(fd);
		}
	});
	
	//触发墙纸更改事件
	$(document).off('click.hte.wallpaper.data-api',
			'.hte-wallpaper-list > ul > li > img');
	$(document).on(
			'click.hte.wallpaper.data-api',
			'.hte-wallpaper-list > ul > li > img',
			function() {
				HteOS.Settings.setWallpaper($(this).attr("src"));
				//HteOS.EventManager.trigger('hte.wallpaper.change',$(this).attr('src'));
			});
	//触发主题更改事件
	$(document).off('click.hte.theme.data-api','.hte-theme-item');
	$(document).on(
			'click.hte.theme.data-api','.hte-theme-item',
			function() {
				var theme = $(this).data('theme');
				HteOS.Settings.setTheme(theme);
				//HteOS.EventManager.trigger('hte.theme.change',theme);
			});
</script>